package com.yswl.yeeduo.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.umeng.analytics.MobclickAgent;
import com.yswl.yeeduo.R;
import com.yswl.yeeduo.ui.bean.ActiviteDetailBean;
import com.yswl.yeeduo.ui.task.WXAuthByUm;

public class SelectSharePopupDialog extends PopupWindow implements OnClickListener {

	private LinearLayout btn_sharewx, btn_sharecricle;
	private View mMenuView;
	private Context mContext;
	private ActiviteDetailBean activeBean;
	public void setActiveBean(ActiviteDetailBean activeBean) {
		this.activeBean = activeBean;
	}

	public SelectSharePopupDialog(Activity context) {
		super(context);
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.popup_layout, null);
		btn_sharewx = (LinearLayout) mMenuView.findViewById(R.id.btn_share_wx);
		btn_sharecricle = (LinearLayout) mMenuView.findViewById(R.id.btn_share_wxcricle);
		// 设置按钮监听
		btn_sharecricle.setOnClickListener(this);
		btn_sharewx.setOnClickListener(this);
		// 设置SelectPicPopupWindow的View
		this.setContentView(mMenuView);
		// 设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.FILL_PARENT);
		// 设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.WRAP_CONTENT);
		// 设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		// 设置SelectPicPopupWindow弹出窗体动画效果
		this.setAnimationStyle(R.style.AnimBottom);
		// 实例化一个ColorDrawable颜色为半透明
//		ColorDrawable dw = new ColorDrawable(0xb0000000);
		ColorDrawable dw = new ColorDrawable(android.R.color.transparent);
		// 设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);
		// mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
		mMenuView.setOnTouchListener(new OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {

				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						dismiss();
					}
				}
				return true;
			}
		});

	}

	@Override
	public void onClick(View v) {
		if (activeBean == null) {
			return;
		}
		WXAuthByUm share = new WXAuthByUm(mContext);
		switch (v.getId()) {
		case R.id.btn_share_wxcricle:
			dismiss();
			MobclickAgent.onEvent(mContext,"user_shareto_wxcricle");
			share.WxShareWxCircleByUm(activeBean);
			break;
		case R.id.btn_share_wx:
			dismiss();
			MobclickAgent.onEvent(mContext,"user_shareto_wxchat");
			share.WxShareByUm(activeBean);
			break;

		default:
			break;
		}
	}

}
